package com.xuelang.pipeline.domain.pipeline.service.imp;

import com.xuelang.pipeline.client.common.exception.BizException;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.dto.TagQuery;
import com.xuelang.pipeline.domain.pipeline.Tag;
import com.xuelang.pipeline.domain.pipeline.repository.TagRepository;
import com.xuelang.pipeline.domain.pipeline.service.TagDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 流水线标签领域服务实现类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Service
public class TagDomainServiceImpl implements TagDomainService {

    @Autowired
    private TagRepository tagRepository;

    @Override
    public PageRecord<Tag> pageList(long currentPage, long pageSize, TagQuery tagQuery) {
        return tagRepository.pageList(currentPage, pageSize, tagQuery);
    }

    @Override
    public List<Tag> list(TagQuery tagQuery) {
        return tagRepository.list(tagQuery);
    }

    @Override
    public List<Tag> listByUuidList(List<String> uuidList) {
        return tagRepository.listByUuidList(uuidList);
    }

    @Override
    public Boolean save(Tag tag) {
        if(existsName(tag.getUuid(), tag.getName())) {
            throw new BizException("name已经存在");
        }
        return tagRepository.save(tag);
    }

    @Override
    public Boolean update(Tag tag) {
        if(existsName(tag.getUuid(), tag.getName())) {
            throw new BizException("name已经存在");
        }
        return tagRepository.update(tag);
    }

    @Override
    public Boolean batchSaveOrUpdate(List<Tag> tagList, String creatorId, Date createTime) {
        return tagRepository.batchSaveOrUpdate(tagList, creatorId, createTime);
    }

    @Override
    public Boolean delete(String uuid) {
        return tagRepository.delete(uuid);
    }

    @Override
    public Tag query(String uuid) {
        return tagRepository.query(uuid);
    }

    @Override
    public List<Tag> queryByUuidList(List<String> uuidList) {
        return tagRepository.queryByUuidList(uuidList);
    }

    @Override
    public Boolean existsName(String uuid, String name) {
        return tagRepository.existsName(uuid, name);
    }
}
